<link rel="stylesheet" type="text/css" href="/static/index/css/pages-addressList.css" />

<script type="text/javascript" src="/static/index/js/pages/city-picker.js"></script>
<script type="text/javascript" src="/static/index/js/pages/addressList.js"></script>

<!--header-->
<div id="account">
	<div class="py-container">
		<div class="yui3-g home">
			<!--左侧列表-->
			<div class="yui3-u-1-6 list">
				<dl>
					<dt><i>·</i> 设置</dt>
					<dd><a href="{:url('index/home/index')}">个人信息</a></dd>
<!--						<dd>账户安全</dd>-->
<!--						<dd>账号绑定 </dd>-->
<!--						<dd>我的级别</dd>-->
					<dd class="active">收货地址</dd>
<!--						<dd>应用授权</dd>-->
<!--						<dd>快捷支付</dd>-->
<!--						<dd>企业发票</dd>-->
<!--						<dd>采购需求单</dd>-->
				</dl>

			</div>
			<!--右侧主内容-->
			<div class="yui3-u-5-6 body">
				<div class="addressList">
					<div class="mt">
						<span class="fl"><strong>我的收货地址</strong></span>
					</div>
				</div>

				<div class="address-detail">
					<div class="addbtn">
						<a data-toggle="modal" data-target=".edit" data-keyboard="false" class="sui-btn btn-bordered btn-xlarge btn-info">新增收货地址</a>
						<span class="topnum">您已创建4 个收货地址，最多可创建20个</span>
					</div>
					<div class="addresses">
					{foreach $data as $v}
						<div class="address-item" address_id = {$v.id}>
							<div class="smt">{$v.consignee}&nbsp;&nbsp;
								{if $v.check == 1}
									<i class="sui-btn btn-warning">默认地址</i>
								{/if}
								<a class="pull-right delete delAdd" style="cursor: pointer;" address_id = {$v.id}>删除</a>
							</div>

							<div class="smc">
								<div class="item">
									<span class="fl label">收货人：</span>
									<div class="detail">{$v.consignee}</div>
									<div class="clearfix"></div>
								</div>

							</div>
							<div class="smc">
								<div class="item">
									<span class="fl label">地址：</span>
									<div class="detail">{$v.address}</div>
									<div class="clearfix"></div>
								</div>
							</div>
							<div class="smc">
								<div class="item">
									<span class="fl label">手机：</span>
									<div class="detail">{$v.phone}</div>
									<div class="clearfix"></div>
								</div>

							</div>
							<div class="pull-right operate">
<!--								<a href="#" data-toggle="modal" data-target=".edit" data-keyboard="false" >编辑</a>-->
							</div>
							<div class="clearfix"></div>
						</div>
					{/foreach}
					</div>

					<!--弹层内容-->
					<!--添加地址-->
					<div  tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade edit">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×</button>
									<h4 id="myModalLabel" class="modal-title">添加收货地址</h4>
								</div>
								<div class="modal-body">
									<form action="{:url('index/home/insertss')}" method="post" class="sui-form form-horizontal">
										<input type="hidden" name="cart_ids" value="{$Think.get.cart_ids}">
										<div class="control-group">
											<label class="control-label">收货人：</label>
											<div class="controls">
												<input type="text" name="consignee" class="input-medium">
												<span class="error" style="color:#ff0000;"></span>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">详细地址：</label>
											<div class="controls">
												<input type="text" name="address" class="input-large">
												<span class="error" style="color:#ff0000;"></span>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">联系电话：</label>
											<div class="controls">
												<input type="text" name="phone" maxlength="11" class="input-medium">
												<span class="error" style="color:#ff0000;"></span>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">默认地址：</label>
											<div class="controls">
												<input type="checkbox" class="input-medium" name="check" value="1">
											</div>
										</div>
										<span style="color:#ff0000;">温馨提醒：请保持信息的准确性</span>
									</form>
								</div>
								<div class="modal-footer">
									<button type="button" class="sui-btn btn-primary btn-large">确定</button>
									<button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">取消</button>
								</div>
							</div>
						</div>
					</div>
			</div>

		</div>
	</div>
</div>

<script>
	$(function(){
		$(".delAdd").click(function(){
			//
			if(!confirm("您确定要删除吗？"))
			{
				return;
			}

			var id = $(this).attr("address_id");
			var that = this;
			$.ajax({
				url:"{:url('index/Home/deleteAdd')}",
				data:"id="+id,
				success:function(res)
				{
					if(res.code != 10000)
					{
						alert(res.msg);
						return;
					}
					$(that).closest(".address-item").remove();
				}
			})

		})

		$(".btn-primary").click(function() {

			var flag = true;

			if($("input[name=consignee]").val() == "") {
				$("input[name=consignee]").parent().find('.error').html("收件人不可以为空亲");
				flag = false;
			}else{
				$("input[name=consignee]").parent().find('.error').html("");
			}

			if($("input[name=address]").val() == "") {
				$("input[name=address]").parent().find('.error').html("地址不可以为空亲");
				flag = false;
			}else{
				$("input[name=address]").parent().find('.error').html("");
			}

			if($("input[name=phone]").val() == "") {
				$("input[name=phone]").parent().find('.error').html("手机号不可以为空亲");
				flag = false;

			}else if(!/^1[3-9]\d{9}$/.test($("input[name=phone]").val())){

				$("input[name=phone]").parent().find('.error').html("手机号格式不正确");
				flag = false;

			}else{
				$("input[name=phone]").parent().find('.error').html("");
			}

			if(flag){
				$(".sui-form").submit();
			}
		})
	})
</script>